package com.codefish.codefishseckill.controller;

import com.codefish.codefishseckill.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 登录前端控制器
 *
 * @author codefish
 * @version 1.0
 * @date 2022/07/05 下午 02:43
 */
@Controller
@Slf4j
public class LoginController {

    @Autowired
    UserService userService;

    @GetMapping({"/login"})
    public String loginPage(@RequestParam(defaultValue = "0", required = false) Integer loginType) {
        if (loginType == 0) {
            return "PasswordLogin";
        } else {
            return "EmailLogin";
        }
    }


    //登录方式一：账号密码登录，Spring Security的UsernamePasswordAuthenticationFilter已封装
//
//    @PostMapping("/doLogin")
//    @ResponseBody
//    public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) {
//        String username = loginVo.getUsername();
//        String password = loginVo.getPassword();
//        if (userService.doLogin(Long.parseLong(username), password, request, response)) {
//            return RespBeanFactory.success("登录成功");
//        } else {
//            throw new GlobalException(RespBeanFactory.fail("用户名或密码错误"));
//        }
//    }

    //登录方式二：邮箱+验证码登录


}
